//24 normal
function swapPairs(head) {
  if (!head || !head.next) return;
  let p1 = head;
  let p2 = head.next;
  let prev = {};
  const phead = prev;
  while (p1 !== null && p2 !== null) {
    const temp = p2.next;
    p1.next = temp;
    p2.next = p1;
    prev.next = p2;

    prev = p1;
    p1 = p1.next;
    p2 = p1 ? p1.next : null;
  }
  return phead.next;
}
console.log(
  swapPairs({
    val: 1,
    next: { val: 2, next: { val: 3, next: { val: 4, next: null } } },
  })
);
console.log(1);
